Skip to content

Conversation

kanoshiou
Copy link
Contributor

@kanoshiou kanoshiou commented Oct 13, 2025

The root cause was that when aggregate columns are pruned and no grouping columns exist, the optimizer creates a LocalRelation with a ConstantNullBlock page using LocalSupplier.of() (which delegates to ImmediateLocalSupplier), but during inline stats execution, this same page gets referenced and released twice - once when the LocalRelation serves as a source for the left-hand side of the InlineJoin, and again when it continues execution on the right-hand side, causing a double release error and connection closure. The CopyingLocalSupplier prevents this by creating a deep copy of the page on each get() call, ensuring proper memory management when the same LocalRelation is used multiple times in inline stats scenarios.

Same issue here as in PropagateEmptyRelation and ReplaceStatsFilteredAggWithEval. Maybe we could use CopyingLocalSupplier only when the LocalRelation is under an inline stats plan and used on the right side — otherwise, stick with ImmediateLocalSupplier. CopyingLocalSupplier does a deep copy, so it could hurt performance.

Closes #135679

- Replace `LocalSupplier.of` with new `CopyingLocalSupplier` in `PruneColumns`
- Add `INLINE_STATS_AFTER_PRUNED_AGGREGATE` capability
- Add test cases for inline stats after aggregate pruning
@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v9.3.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Oct 13, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Oct 13, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Oct 13, 2025
@bpintea bpintea requested review from astefan and bpintea October 13, 2025 11:23
@kanoshiou kanoshiou changed the title ESQL: Fix connection closed in inline stats after pruned aggregates ESQL: Fix double release in inline stats when LocalRelation is reused Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL external-contributor Pull request authored by a developer outside the Elasticsearch team Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ES|QL: INLINE STATS leads to "can't build page out of released blocks"

3 participants